# Maintainer: justforlxz <justforlxz@gmail.com>
pkgname=deepin-desktop-schemas-git
pkgver=5.10.2.r8.gd9e09d5
pkgrel=1
sourcename=deepin-desktop-schemas
sourcetars=("$sourcename"_"$pkgver".tar.xz vendor.tar.gz)
sourcedir="$sourcename"
useforobs=1
pkgdesc='GSettings deepin desktop-wide schemas'
arch=('any')
url="https://github.com/linuxdeepin/deepin-desktop-schemas"
license=('GPL3')
depends=('dconf' 'deepin-gtk-theme-git' 'deepin-icon-theme-git' 'deepin-sound-theme-git')
makedepends=('git' 'python' 'go')
conflicts=('deepin-artwork-themes' 'deepin-desktop-schemas')
provides=('deepin-desktop-schemas')
groups=('deepin-git')
source=("${sourcetars[@]}")
sha512sums=('SKIP' 'SKIP')

prepare() {
  export GOPATH="$srcdir/build:/usr/share/gocode"
  cd $sourcedir

  # fix default background url
  sed -i "s#/usr/share/backgrounds/default_background.jpg#/usr/share/backgrounds/deepin/desktop.jpg#" \
    overrides/common/com.deepin.wrap.gnome.desktop.override schemas/com.deepin.dde.appearance.gschema.xml
  # fix network checker url
  sed -i "s#'https://www.chinauos.com', 'https://www.uniontech.com'#'https://www.archlinux.org'#" schemas/com.deepin.dde.network-utils.gschema.xml
}

build() {
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  if [[ ! -n "$useforobs" ]];then
    export GOFLAGS="-buildmode=pie -trimpath -modcacherw -mod=readonly"
    go mod tidy
  else
    export GOFLAGS="-buildmode=pie -trimpath -modcacherw -mod=vendor"
    mv "$srcdir"/vendor "$srcdir"/"$sourcedir"/vendor
  fi
  cd $sourcedir
  make ARCH=x86
}

check() {
  cd $sourcedir
  make test
}

package() {
  cd $sourcedir
  make DESTDIR="$pkgdir" install
}
